class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) 
    {
        if(strs.empty())
            return "";
        string tmp(strs[0].begin(),strs[0].end());
        for(int i=0;i<strs.size()-1;i++)
        {
            int j=0;
            while(j<strs[i].size()&&j<strs[i+1].size())
            {
                if(strs[i][j]==strs[i+1][j]&&j<=tmp.size())
                    j++;
                else
                {
                    break;
                }               
            }
            if(j<=tmp.size())
                tmp.resize(j);
        }
            return tmp;    
    }
};